#include<bits/stdc++.h>
using namespace std;
int a[200009],n;
long long an=0;
void Z(int w,int lr,int lb,long long ans)
{
    if(w==n+1)
    {
        an=max(ans,an);
        return;
    }
    if(a[lr]==a[w]&&lr!=0)Z(w+1,w,lb,ans+a[w]);
    else Z(w+1,w,lb,ans);
    if(a[lb]==a[w]&&lb!=0)Z(w+1,lr,w,ans+a[w]);
    else Z(w+1,lr,w,ans);
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    cin>>t;
    for(int kk=1;kk<=t;kk++)
    {
        an=0;
        cin>>n;
        for(int i=1;i<=n;i++)cin>>a[i];
        Z(1,0,0,0);
        cout<<an<<"\n";
    }
    return 0;
}
